package com.winit.requirement.repository;

import com.winit.requirement.model.ReqDebunker;
import com.winit.requirement.model.ReqRemark;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@Component
public class ReqDebunkRepositoryExt {
    @PersistenceContext
    private EntityManager entityManager;

    @Transactional
    public int update(ReqDebunker debunker) {
        ReqDebunker entity = entityManager.find(ReqDebunker.class, debunker.getId());
        if (entity == null) {
            return 0;
        }
        boolean update = false;
        if (debunker.getDebunkDesc() != null) {
            update = true;
            entity.setDebunkDesc(debunker.getDebunkDesc());
        }
        if (debunker.getIsImprove() != null) {
            update = true;
            entity.setIsImprove(debunker.getIsImprove());
        }
        if (!update) {
            return 0;
        }
        entityManager.merge(entity);
        entityManager.flush();
        return 1;
    }
}
